//
//  NullStateView.m
//  Yanwei
//
//  Created by Seven-Augus on 2017/6/13.
//  Copyright © 2017年 DCloud. All rights reserved.
//

#import "NullStateView.h"
#import "UILabel+Additions.h"

@interface NullStateView ()

@property (nonatomic, strong) UILabel *IFStringLabel; // 图标文字
@property (nonatomic, strong) UILabel *describeLabel; // 描述
@property (nonatomic, strong) UIButton *IFButton;
@property (nonatomic, strong) UILabel *onlyDescribeLabel;

@end

@implementation NullStateView

- (instancetype)initWithFrame:(CGRect)frame fromViewType:(NSInteger)fromViewType {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = Color244;
        switch (fromViewType) {
            case NoSearchResultsType:
                [self initView:StoreSearchArticleOrAuthorEmptyIFString describeString:@"暂未找到合适的商品\n试试重新输入商品名称，或联系在线客服"];
                break;
            case NoNavigationSearchResultsType:
                [self initView:StoreSearchArticleOrAuthorEmptyIFString describeString:@"暂未找到合适的商品\n试试重新输入筛选条件，或联系在线客服"];
                break;
                
            case NoSearchShopResultsType:
                [self initView:StoreSearchArticleOrAuthorEmptyIFString describeString:@"暂未找到合适的店铺\n试试重新输入店铺名称，或联系在线客服"];
                break;
            case NoSearchOrderResultsType:
                [self initView:StoreSearchArticleOrAuthorEmptyIFString describeString:@"未查询到相关订单"];
                break;
            case NetworkTimeoutType:
                [self initView:NetworkTimeoutIFString describeString:@"网络连接超时"];
            case RequestDataGoBackFailType:
                [self initView:RequestDataGoBackIFString describeString:@"服务器开小差了,请稍后再试"];
                break;
            case NetworkDisconnectType:
                [self initView:NetworkTimeoutIFString describeString:@"网络断开连接"];
                break;
            case ShoppingCartEmptyType:
                [self initView:ShoppingCartEmptyIFString describeString:@"去添加点什么吧"];
                break;
            case OrderListEmptyType:
                [self initView:ShoppingListEmptyIFString describeString:@"您还没有相关订单"];
                break;
            case RecommendBusinessmanEmptyType:
                [self initView:RecommendBusinessmanEmptyIFString describeString:@"还没有推荐过供应商哦\n快点击右上角，进行添加吧"];
                break;
            case MessageEmpTyType:
                [self initView:MessageEmptyIFString describeString:@"暂无消息哦"];
                break;
            case SubscribeListEmptyType:
                [self initView:EventEmptyIFString describeString:@"抱歉，目前暂无征订活动\n请您耐心等待"];
                break;
            case EventEmptyType:
                [self initView:EventEmptyIFString describeString:@"抱歉，目前暂无会议活动\n请您耐心等待"];
                break;
            case EnergizingActivityListEmptyType:
                [self initView:EventEmptyIFString describeString:@"暂无数据"];
                break;
            case MySubscriptionListEmptyType:
                [self initView:MySubscriptionListIFString describeString:@"还没有关注的人"];
                break;
            case CollectionListEmptyType:
                [self initView:CollectionListIFString describeString:@"您还没有收藏过文章哦"];
                break;
            case ShopCollectionListEmptyType:
                [self initView:ShopCollectionListIFString describeString:@"您还没有收藏过商品哦"];
                break;
            case StoreCouponsEmptyType:
                [self initView:StoreCouponsListIFString describeString:@"暂时没有优惠券哦~"];
                break;
            case StoreListEmptyType:
                [self initView:StoreListIFString describeString:@"暂无商品"];
                break;
            case StoreAppraiseEmptyType:
                [self initView:StoreAppraiseEmptyIFString describeString:@"暂无相关评论"];
                break;
            case StoreSearchArticleEmptyType:
                [self initView:StoreSearchArticleOrAuthorEmptyIFString describeString:@"没有搜索到相关文章\n您可以试试换下搜索词"];
                break;
            case StoreSearchAuthorEmptyType:
                [self initView:StoreSearchArticleOrAuthorEmptyIFString describeString:@"没有搜索到相关作者\n您可以试试换下搜索词"];
                break;
            case NewFansRosePowderStrategyType:
                [self initViewWithPureText:@"你这么优秀，怎么能没有粉丝？\n点击“涨粉攻略”按钮，获取攻略哦"];
                break;
            case NewFansCommissionType:
                [self initViewWithPureText:@"还没有提成奖励哦\n提成攻略：第一步，涨粉，涨粉！\n第二步，鼓励粉丝购物，购物！"];
                break;
            case NewFansGroupSentMessageType:
                [self initViewWithPureText:@"还没有给粉丝群发过消息\n点击“群发消息”，开启与粉丝的联系吧！"];
                break;
            case ShareArticleListEmptyType:
                [self initView:CollectionListIFString describeString:@"你还没有转发过文章"];
                break;
            case ShareArticleStatisticalListEmptyType:
                [self initView:CollectionListIFString describeString:@"你的文章还没有人阅读过"];
                break;
            case ShareCommodityListEmptyType:
                [self initView:ShopCollectionListIFString describeString:@"没有分享记录，快去分享吧"];
                break;
            case ShareCommodityStatisticalListEmptyType:
                [self initView:ShopCollectionListIFString describeString:@"没有浏览记录"];
                break;
            case TASubscriptionListEmptyType:
                [self initView:TASubscriptionListEmptyIFString describeString:@"TA暂时还没有关注的人喔"];
                break;
            case SubscriptionTaListEmptyType:
                [self initView:TASubscriptionListEmptyIFString describeString:@"暂时还没有关注TA的人喔"];
                break;
            case ObtainGuestForBuiedListEmptyType:
                [self initView:ShopCollectionListIFString describeString:@"暂无客户，赶快将好商品\n分享出去，客户线索一手掌握"];
                break;
            case ObtainGroupPurshaseOrderListEmptyType:
                [self initView:ShopCollectionListIFString describeString:@"暂无内容"];
                break;
            case IdentityInfoListEmptyType:
                [self initView:IdentityInfoListIFString describeString:@"暂无实名信息"];
                break;
            case GoodsAndCashCouponsListEmptyType:
                [self initView:GoodsAndCashInfoListIFString describeString:@"还没有可用代金券"];
                break;
            case PreGroupPurshaseListEmptyType:
                [self initView:N_DOWNGROUPPURSEFINISH describeString:@"暂时没有将要开启的拼团，敬请期待~"];
                break;
            default:
                break;
        }
    }
    return self;
}

/** 初始化视图 */
- (void)initView:(NSString *)iconFontString describeString:(NSString *)describeString {
    self.IFStringLabel.text = iconFontString;
    self.describeLabel.text = describeString;
    [UILabel changeLineSpaceAndCenterForLabel:self.describeLabel WithSpace:6.0];
    if ([iconFontString isEqualToString:RecommendBusinessmanEmptyIFString] || [iconFontString isEqualToString:EventEmptyIFString] || [iconFontString isEqualToString:StoreSearchArticleOrAuthorEmptyIFString]) {
        self.IFStringLabel.textColor = Color217;
    }
    if ([iconFontString isEqualToString:StoreAppraiseEmptyIFString]) {
        [self.IFStringLabel mas_updateConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.mas_centerY).with.multipliedBy(0.35);
        }];
    }
    
    if ([describeString isEqualToString:@"网络连接超时"] || [describeString isEqualToString:@"网络断开连接"]) {
        [self.IFButton setTitle:@"重新加载" forState:UIControlStateNormal];
    }
    if ([describeString isEqualToString:@"服务器开小差了,请稍后再试"]) {
        [self.IFButton setTitle:@"点击重试" forState:UIControlStateNormal];
    }
    
    if ([describeString isEqualToString:@"暂无内容"]) {
        [self.IFButton setTitle:@"去参团" forState:UIControlStateNormal];
        
        [self.IFButton setTitleColor:Color175030 forState:UIControlStateNormal]; 
        self.IFButton.titleLabel.font = APPFONT(15);
        self.IFButton.layer.cornerRadius = 17.5;
        self.IFButton.layer.borderColor = Color175030.CGColor;
        self.IFButton.layer.borderWidth = 0.5;
        
        [_IFButton mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.describeLabel.mas_bottom).with.offset(30);
            make.centerX.equalTo(self.describeLabel);
            make.width.mas_equalTo(105);
            make.height.mas_equalTo(35);
        }];
        
    }
    
    if ([describeString isEqualToString:@"暂无实名信息"]) {
        [self.IFButton setTitle:@"去添加" forState:UIControlStateNormal];
        
        [self.IFButton setTitleColor:Color0108183 forState:UIControlStateNormal];
        self.IFButton.titleLabel.font = APPFONT(15);
        self.IFButton.layer.cornerRadius = 17.5;
        self.IFButton.layer.borderColor = Color0108183.CGColor;
        self.IFButton.layer.borderWidth = 0.5;
        
        [_IFButton mas_updateConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.describeLabel.mas_bottom).with.offset(30);
            make.centerX.equalTo(self.describeLabel);
            make.width.mas_equalTo(105);
            make.height.mas_equalTo(35);
        }];
    }
}
- (void)initViewWithPureText:(NSString *)describeString {
    self.onlyDescribeLabel.text = describeString;
    [UILabel changeLineSpaceAndCenterForLabel:self.onlyDescribeLabel WithSpace:6.0];
}


#pragma mark - progress
- (void)progressIFButton {
    if (self.nullStateViewBlock) {
        self.nullStateViewBlock();
    }
}


#pragma mark - 懒加载
- (UILabel *)IFStringLabel {
    if (!_IFStringLabel) {
        _IFStringLabel = [UILabel new];
        _IFStringLabel.font = ICONFONT(70);
        if (ScreenWidth < 375) {
            _IFStringLabel.font = ICONFONT(60);
        }
        _IFStringLabel.textColor = Color217;
        [self addSubview:_IFStringLabel];
        [_IFStringLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.mas_centerY).with.multipliedBy(0.6);
            make.centerX.equalTo(self.mas_centerX);
        }];
    }
    return _IFStringLabel;
}
- (UILabel *)describeLabel {
    if (!_describeLabel) {
        _describeLabel = [UILabel new];
        _describeLabel.font = ICONFONT(15);
        _describeLabel.numberOfLines = 0;
        _describeLabel.textColor = Color140;
        _describeLabel.textAlignment = NSTextAlignmentCenter;
    
        [self addSubview:_describeLabel];
        [_describeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.IFStringLabel.mas_bottom).with.offset(20);
            make.centerX.equalTo(self.IFStringLabel);
        }];
    }
    return _describeLabel;
}
- (UIButton *)IFButton {
    if (!_IFButton) {
        _IFButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_IFButton setTitleColor:Color140 forState:UIControlStateNormal];
        _IFButton.titleLabel.font = APPFONT(14);
        _IFButton.layer.cornerRadius = 4;
        _IFButton.layer.borderColor = RGBACOLOR(204, 204, 204, 1).CGColor;
        _IFButton.layer.borderWidth = 1;
        [_IFButton addTarget:self action:@selector(progressIFButton) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_IFButton];
        [_IFButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.describeLabel.mas_bottom).with.offset(40);
            make.centerX.equalTo(self.describeLabel);
            make.width.equalTo(self.describeLabel);
            make.height.mas_equalTo(31);
        }];
    }
    return _IFButton;
}
- (UILabel *)onlyDescribeLabel {
    if (!_onlyDescribeLabel) {
        _onlyDescribeLabel = [UILabel new];
        _onlyDescribeLabel.font = ICONFONT(15);
        _onlyDescribeLabel.numberOfLines = 0;
        _onlyDescribeLabel.textColor = Color140;
        _onlyDescribeLabel.textAlignment = NSTextAlignmentCenter;
        
        [self addSubview:_onlyDescribeLabel];
        [_onlyDescribeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.centerX.equalTo(self);
        }];
    }
    return _onlyDescribeLabel;
}

@end
